<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>两个列表的最小索引总和</title>
</head>
<body>
  <script>
    let list1 = ['Shogun', 'Tapioca Express', 'Burger King', 'KFC']
    let list2 = ['Piatti', 'The Grill at Torrey Pines', 'Hungry Hunter Steakhouse', 'Shogun']
    function fn(list1, list2) {
      let map = {};
      let keysArr = [];
      list1.forEach((item, index) => {
        let index2 = list2.indexOf(item)
        if (index2 > -1) {
          const total = index + index2
          if (map[total]) {
            map[total].push(item)
          } else {
            map[total] = [item]
          }
        }
      })
      keysArr = Object.keys(map)
      keysArr.sort((a, b) => a - b)
      return map[keysArr[0]]
    }
    console.log(fn(list1, list2))
  </script>
</body>
</html>